package com.apartment.own.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnOrdExtraCharge;
import com.apartment.own.service.IOwnOrdExtraChargeService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 额外费用Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/charge")
public class OwnOrdExtraChargeController extends BaseController
{
    @Autowired
    private IOwnOrdExtraChargeService ownOrdExtraChargeService;

    /**
     * 查询额外费用列表
     */
    @PreAuthorize("@ss.hasPermi('own:charge:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnOrdExtraCharge ownOrdExtraCharge)
    {
        startPage();
        List<OwnOrdExtraCharge> list = ownOrdExtraChargeService.selectOwnOrdExtraChargeList(ownOrdExtraCharge);
        return getDataTable(list);
    }

    /**
     * 导出额外费用列表
     */
    @PreAuthorize("@ss.hasPermi('own:charge:export')")
    @Log(title = "额外费用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnOrdExtraCharge ownOrdExtraCharge)
    {
        List<OwnOrdExtraCharge> list = ownOrdExtraChargeService.selectOwnOrdExtraChargeList(ownOrdExtraCharge);
        ExcelUtil<OwnOrdExtraCharge> util = new ExcelUtil<OwnOrdExtraCharge>(OwnOrdExtraCharge.class);
        return util.exportExcel(list, "charge");
    }

    /**
     * 获取额外费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:charge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownOrdExtraChargeService.selectOwnOrdExtraChargeById(id));
    }

    /**
     * 新增额外费用
     */
    @PreAuthorize("@ss.hasPermi('own:charge:add')")
    @Log(title = "额外费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnOrdExtraCharge ownOrdExtraCharge)
    {
        return toAjax(ownOrdExtraChargeService.insertOwnOrdExtraCharge(ownOrdExtraCharge));
    }

    /**
     * 修改额外费用
     */
    @PreAuthorize("@ss.hasPermi('own:charge:edit')")
    @Log(title = "额外费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnOrdExtraCharge ownOrdExtraCharge)
    {
        return toAjax(ownOrdExtraChargeService.updateOwnOrdExtraCharge(ownOrdExtraCharge));
    }

    /**
     * 删除额外费用
     */
    @PreAuthorize("@ss.hasPermi('own:charge:remove')")
    @Log(title = "额外费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownOrdExtraChargeService.deleteOwnOrdExtraChargeByIds(ids));
    }
}
